home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / MacTCP class library / MacTCP class headers / CDNR.h next >
Text File  |  1992-10-26  |  4KB  |  131 lines

  1. /*
  2.  
  3.   CDNR.h
  4.   Superclass:    CMacTCPDriver
  5.  
  6.      Dynamic name resolution implementation.
  7.  
  8.   Copyright © NCSA, University of Illinois;    June 2, 1992
  9.   Igor Livshits
  10.   
  11.   This code may be used, modified, and distributed free of charge and obligation.
  12.   
  13. */
  14.  
  15. #define    _H_CDNR                                        //    Include this file only once
  16.  
  17. #include    "CMacTCPDriver.h"                //    Superclass definitions
  18. #include    "CIsleResFile.h"
  19.  
  20.  
  21. #define kAlternateAddresses            4
  22.  
  23. #define    kControlPanel            'cdev'    //    File type for control panels
  24. #define    kMacTCP                        'mtcp'    //    File creator for the MacTCP control panel
  25. #define    kNameResolver            'dnrp'    //    Resource type of the name resolver
  26. #define    kNameResolverID        1                //    Resource ID of the name resolver calls
  27. #define    kNotFound                    -1            //    Our search was unsuccessful
  28. #define    kBasicVersion            1                //    A safe assumption
  29. #define    kDefault                    0                //    Default specification
  30. #define    kSystem603                0x0603    //    System version 6.0.3 (required for MacTCP)
  31.  
  32. #define kOpen                            1L            //    Procedure assingments
  33. #define kClose                        2L
  34. #define kStringToAddress    3L
  35. #define    kAddressToString    4L
  36. #define    kEnumerateCache        5L
  37. #define kAddressToName        6L
  38.  
  39. #define    kDNRError                    2367        //    DNR specific errors
  40. #define    kNoResolver                1                //    Could not access the resolver
  41.  
  42. typedef enum AddressClasses                //    Address classes
  43. {
  44.     kAddress= 1,                                            //    The value is an address
  45.     kNameServer,                                            //    The value is a name
  46.     kCanonicalName= 5,                                //    The vlaue is an alias for the canonical name
  47.     kLastClass = 65535                                //    Upper bound
  48. }; 
  49.  
  50. typedef struct hostInfo                        //    Types used by MacTCP (from the MacTCP Documentation Kit)
  51. {
  52.     long        returnCode;                                //    Are the result fields valid?
  53.     char        name[255];                                //    The official name
  54.     ip_addr address[kAlternateAddresses];    //    List of addresses for the name
  55. }hostInfoRec, *hostInfoPtr;
  56.  
  57. typedef struct cacheEntryRecord        //    The cache contents
  58. {
  59.     char*                                name;                    //    The name, of course
  60.     unsigned short            type;                    //    The type of the entry        
  61.     enum AddressClasses    entryClass;        //    The class of the entry
  62.     unsigned long                timeLeft;            //    The time that the entry has to live in the cache relative to current time
  63.     union
  64.     {
  65.         char*            name;
  66.         ip_addr        address;
  67.     } rData;                                                    //    Specified by the type field
  68. };
  69.  
  70. /*===---------------===*/
  71.  
  72. class CDNR : public CMacTCPDriver
  73. Begin
  74. public:
  75.     CIsleResFile*    fileMacTCP;                            //    The TCP driver
  76.     Handle                codeHandle;                            //    A handle to the code resource of dnr routines
  77.     OSErrProcPtr    resolver;                                //    A pointer to the code resource of dnr routines
  78.     
  79.  
  80.     void    IDNR                                                        //    Initialize the name resolver
  81.             (    char*                            fileName                //    Name of the hosts file (may be null for a default)
  82.             );
  83.             
  84.     void    Dispose                                                    //    We are done with the name resolver
  85.             (    void                                                            //    No arguments
  86.             );
  87.             
  88.     
  89.     OSErr    StringToAddress                                    //    Convert from a string to an address
  90.             (    char*                         hostName,                //    Host's name
  91.                 struct hostInfo*    result,                    //    The information record for the host
  92.                 ProcPtr                        ResultProc,            //    Pointer to a procedure to handle results
  93.                 char*                            done                        //    Set when non-cache call completes
  94.             );
  95.  
  96.     void    AddressToString                                    //    Convert from an address to a string
  97.             (    ip_addr                        address,                //    The numerical address
  98.                 char*                            addressStr            //    The address as a string
  99.             );
  100.  
  101.     void    EnumerateCache                                    //    Enumerate the entries in the cache
  102.             (    ProcPtr                        EnumResultProc,    //    Pointer to a procedure to handle results
  103.                 char*                            done                        //    Set when non-cache call completes
  104.             );
  105.  
  106.     OSErr    AddressToName                                        //    Acquire a canonical name from an address
  107.             (    ip_addr                     address,                //    The numerical address
  108.                 struct hostInfo*    result,                    //    The information record for the host
  109.                 ProcPtr                        ResultProc,            //    Pointer to a procedure to handle results
  110.                 char*                            done                        //    Set when non-cache call completes
  111.             );
  112. End;
  113.  
  114. /*===---------------===*/
  115. /*=====================*/
  116. /*===---------------===*/
  117.  
  118. pascal void    EnumResultProc                            //    Called with a pointer to a cache entry
  119.             (    struct cacheEntryRecord*    cacheEntryRecordPtr,    //    The entry
  120.                 char*                         done                        //    Set to true when call completes
  121.             );
  122.  
  123. pascal void    ResultProc                                //    Called with an appropriate return code and information
  124.             (    struct hostInfo*    hostInfoPtr,    //    Pointer to host information
  125.                 char*                         done                    //    Set to true when call completes
  126.             );
  127.  
  128. /*===---------------===*/
  129. /*=====================*/
  130.  
  131. extern    tSystem    gSystem;                            //    System information